<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index()
    {
        $this->display();
    }

    //管理员列表
    public function admin()
    {
    	$admins = M('gy_admin')->select();
    	$this->assign('admins',$admins);

    	$this->display();
    }
    //管理员编辑
    public function adminedit()
    {
    	if (IS_POST) {
    		$id = I('post.id');
    		$password = I('post.password');
    		$repassword = I('post.repassword');

    		if ($password != $repassword) {
    			$arr = array(
    				'error' => 0,
    				'info' => '两次密码输入不一样'
    				);
    			echo json_encode($arr);
    			exit;
    		}

    		$data['password'] = md5($password);
    		$res = M('gy_admin')->where(['id'=>$id])->save($data);
    		if ($res) {
    			$arr = array(
    				'error' => 1,
    				'info' => '更新成功'
    				);
    			echo json_encode($arr);
    		}else {
    			$arr = array(
    				'error' => 0,
    				'info' => '更新失败'
    				);
    			echo json_encode($arr);
    		}

    	}else {

	    	$id = I('get.id');
	    	$admin_info = M('gy_admin')->where(['id'=>$id])->find();
	    	$this->assign('admin_info',$admin_info);

	    	$this->display();
    	}
    }














}